import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class MultiListener extends Applet implements ActionListener {
    TextArea topTextArea;
    TextArea bottomTextArea;
    Button button1,button2;

    public void init() {
	Label l = null;
	GridBagLayout gridbag = new GridBagLayout();
	GridBagConstraints c = new GridBagConstraints();
	setLayout(gridbag);
	c.fill = GridBagConstraints.BOTH;
	c.gridwidth = GridBagConstraints.REMAINDER;
	l = new Label("What MultiListener hears:");
	gridbag.setConstraints(l, c);
	add(l);

	c.weighty = 1.0;
	topTextArea = new TextArea(5,20);
	topTextArea.setEditable(false);
	gridbag.setConstraints(topTextArea, c);
	add(topTextArea);

	c.weightx = 0.0;
	c.weighty = 0.0;
	l = new Label("What Eavesdropper hears:");
	gridbag.setConstraints(l, c);
	add(l);

	c.weighty = 1.0;
	bottomTextArea = new TextArea(5, 20);
	bottomTextArea.setEditable(false);
	gridbag.setConstraints(bottomTextArea, c);
	add(bottomTextArea);

	c.weightx = 1.0;
	c.weighty = 0.0;
	c.gridwidth = 1;
	c.insets = new Insets(10, 10, 0, 10);
	button1 = new Button("Blab blah blah");
	gridbag.setConstraints(button1, c);
	add(button1);

	c.gridwidth = GridBagConstraints.REMAINDER;
	button2 = new Button("You don't say!");
	gridbag.setConstraints(button2, c);
	add(button2);

	button1.addActionListener(this);
	button2.addActionListener(this);

	button2.addActionListener(new Eavesdropper(bottomTextArea));
	
    }
    public void actionPerformed(ActionEvent e) {
	topTextArea.append(e.getActionCommand() + "\n");
	
    }
}

class Eavesdropper implements ActionListener {
    TextArea myTextArea;
    public Eavesdropper(TextArea ta) {
	myTextArea = ta;
    }
    public void actionPerformed(ActionEvent e) {
	myTextArea.append(e.getActionCommand() + "\n");
    }
}
public class MultiListeners {
   public static void main(String[] args) {
      MultiListener mul = new MultiListener();
   }
}
